/**
 * 
 */
package com.opengroupe.util;

import java.util.Collection;
import java.util.Map;
import java.util.Set;

import com.opengroupe.entities.Candidat;
import com.opengroupe.entities.Question;
import com.opengroupe.entities.Reponse;

/**
 * @author MMB11447
 *
 */
public class ResultatQuestionnaire {
	
	private Candidat candidat;
	
	private Map<Question, Set<Reponse>> questionReponses;
	
	private Map<Question, Boolean> resultat;
	
	private double pourcentage;

	/**
	 * Default class
	 */
	public ResultatQuestionnaire() {
	}

	/**
	 * @param candidat
	 * @param questionReponses
	 * @param resultat
	 */
	public ResultatQuestionnaire(Candidat candidat,
			Map<Question, Set<Reponse>> questionReponses,
			Map<Question, Boolean> resultat) {
		super();
		this.candidat = candidat;
		this.questionReponses = questionReponses;
		this.resultat = resultat;
		buildPourcentage();
	}

	/**
	 * @return the candidat
	 */
	public Candidat getCandidat() {
		return candidat;
	}

	/**
	 * @param candidat the candidat to set
	 */
	public void setCandidat(Candidat candidat) {
		this.candidat = candidat;
	}

	/**
	 * @return the questionReponses
	 */
	public Map<Question, Set<Reponse>> getQuestionReponses() {
		return questionReponses;
	}

	/**
	 * @param questionReponses the questionReponses to set
	 */
	public void setQuestionReponses(Map<Question, Set<Reponse>> questionReponses) {
		this.questionReponses = questionReponses;
	}

	/**
	 * @return the resultat
	 */
	public Map<Question, Boolean> getResultat() {
		return resultat;
	}

	/**
	 * @param resultat the resultat to set
	 */
	public void setResultat(Map<Question, Boolean> resultat) {
		this.resultat = resultat;
	}

	/**
	 * @return the pourcentage
	 */
	public double getPourcentage() {
		return pourcentage;
	}

	/**
	 * @param pourcentage the pourcentage to set
	 */
	public void setPourcentage(double pourcentage) {
		this.pourcentage = pourcentage;
	}

	/**
	 * Calculates the percentage of correct answers
	 */
	private void buildPourcentage() {
		int count = 0;
		Collection<Boolean> goods = resultat.values();
		for(Boolean bool: goods) {
			if(bool) {
				count++;
			}
		}

		double percentage = 100.0 * count / goods.size();
		setPourcentage(percentage);
	}

}
